//
//  ChecklistRequestGPSAlertView.swift
//  ezyform
//
//  Created by Moennig Q on 19/4/2022.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SnapKit
class ChecklistRequestGPSAlertView: UIView {
    var moreInfoBtnClosure: (()->Void)?
    var settingsBtnClosure: (()->Void)?
    var okBtnClosure: (()->Void)?
    let checkBtn = CheckboxButton(title: "Don’t remind me of this job", hexstr: "#292D32B2")
    //IB init
    required init?(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
    }
    //纯代码创建
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUpView()
    }
    private func setUpView() {
        self.backgroundColor = UIColor.black.withAlphaComponent(0.8)
        //back view
        let backView = UIView()
        backView.backgroundColor = UIColor.white
        self.addSubview(backView)
        backView.layer.cornerRadius = Constant.BackViewCornerRadius
        backView.snp.makeConstraints { (make) in
            make.width.equalTo(300)
            make.height.greaterThanOrEqualTo(0)
            make.center.equalToSuperview()
        }
        //titile
        let descripLabel = ContentLabel(R.font.interMedium(size: 15))
        descripLabel.text = "Location data collected by the current checklist helps us to authenticate your on-site obligations and will only be used for CER auditing purposes."
        descripLabel.numberOfLines = 0
        descripLabel.textAlignment = NSTextAlignment.left
        backView.addSubview(descripLabel)
        descripLabel.snp.makeConstraints { (make) in
            make.top.left.equalTo(24)
            make.right.equalTo(-24)
            make.height.greaterThanOrEqualTo(0)
        }
        //moreInfomation btn
        let moreInfoLabel = ContentLabel(R.font.interMedium(size: 15),hexStr: "#379657")
        moreInfoLabel.text = "More Information"
        backView.addSubview(moreInfoLabel)
        moreInfoLabel.snp.makeConstraints { (make) in
            make.top.equalTo(descripLabel.snp.bottom).offset(10)
            make.left.equalTo(descripLabel)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //right arrow
        let moreRightArrow = UIImageView(image: UIImage(named: "installation_detail_spv_tip_right_arrow"))
        backView.addSubview(moreRightArrow)
        moreRightArrow.snp.makeConstraints { (make) in
            make.left.equalTo(moreInfoLabel.snp.right)
            make.centerY.equalTo(moreInfoLabel)
            make.height.width.equalTo(24)
        }
        //Don’t remind me of this job
        backView.addSubview(checkBtn)
        checkBtn.snp.makeConstraints { (make) in
            make.top.equalTo(moreInfoLabel.snp.bottom).offset(25)
            make.left.equalTo(descripLabel)
            make.right.lessThanOrEqualTo(descripLabel)
            make.height.greaterThanOrEqualTo(0)
        }
        //
        //horizonal line view
        let horizonalLineView = UIView()
        horizonalLineView.backgroundColor = UIColor(red: 0.86, green: 0.86, blue: 0.86, alpha: 1)
        backView.addSubview(horizonalLineView)
        horizonalLineView.snp.makeConstraints { (make) in
            make.top.equalTo(checkBtn.snp.bottom).offset(25)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        //
        //vertial line view
        let vertialLineView = UIView()
        vertialLineView.backgroundColor = UIColor(red: 0.86, green: 0.86, blue: 0.86, alpha: 1)
        backView.addSubview(vertialLineView)
        vertialLineView.snp.makeConstraints { (make) in
            make.top.equalTo(horizonalLineView.snp.bottom).offset(4)
            make.height.equalTo(48)
            make.width.equalTo(1)
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-4)
        }
        //No button
        let okBtn = ViewFactory.shared.generateButtonOnAlertView(R.string.localizable.oK())
        backView.addSubview(okBtn)
        okBtn.snp.makeConstraints { (make) in
            make.top.equalTo(horizonalLineView)
            make.left.equalToSuperview()
            make.right.equalTo(vertialLineView)
            make.bottom.equalToSuperview()
        }

        //settings button
        let settingsBtn = ViewFactory.shared.generateButtonOnAlertView(R.string.localizable.settings())
        backView.addSubview(settingsBtn)
        settingsBtn.snp.makeConstraints { (make) in
            make.top.equalTo(horizonalLineView)
            make.left.equalTo(vertialLineView.snp.right)
            make.right.bottom.equalToSuperview()
        }
        //
        let tapBGesture = UITapGestureRecognizer(target: self, action: #selector(moreInfoBtnClick))
        moreInfoLabel.addGestureRecognizer(tapBGesture)
        settingsBtn.addTarget(self, action: #selector(settingsBtnClick), for: UIControl.Event.touchUpInside)
        okBtn.addTarget(self, action: #selector(okBtnClick), for: UIControl.Event.touchUpInside)
    }
    @objc func okBtnClick(){
        self.removeFromSuperview()
        self.okBtnClosure?()
    }
    @objc func settingsBtnClick(){
        self.removeFromSuperview()
        self.settingsBtnClosure?()
    }
    @objc func moreInfoBtnClick(){
        self.moreInfoBtnClosure?()
    }
}
